package io.xxx.xbutler.web.controller;

import io.xxx.xbutler.service.CallbackService;
import io.xxx.xbutler.web.controller.form.CallbackReloadForm;
import io.xxx.xbutler.web.controller.form.CallbackResendForm;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/callback")
public class CallbackController {

    @Resource
    private CallbackService callbackService;

    @PostMapping("/resend")
    public void resend(@RequestBody @Validated CallbackResendForm form) {
        callbackService.resend(form.getIds(), form.getTypes(), form.getStatus());
    }

    @PostMapping("/reload")
    public void reload(@RequestBody @Validated CallbackReloadForm form) throws IOException {
        callbackService.reload(form.getDates(), form.getResend());
    }
}
